
const requestMode = require('../../../js/requestsMode.js');
const session = require('../../../js/session.js');
var Tools = require('../../../js/Tools.js');
Page({
  /**
   * 页面的初始数据
   */
  data: {
    dataSource : [],
      page : 0,
      pageTotal : 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      this.setData({
          page : 0,
          pageTotal : 0
      });
    this.getDealRecordList(1);
  },
  getDealRecordList : function (page) {
        let that = this;
        Tools.showLoaddingDefault();
        requestMode.sendRequest('member/transactions','POST',{ page: page },{sKey : session.get('sKey')}).then(function (getDealRecordSuccess) {
            Tools.hideLoaddingToast();
            let code = getDealRecordSuccess.data.code;
            if(code == 200){
                let getDealRecordData = getDealRecordSuccess.data.data.list;
                let pageTotal = getDealRecordSuccess.data.data.page_total;
                let getPageData = that.data.dataSource;
                getPageData = getPageData.concat(getDealRecordData);
                that.setData({
                    dataSource : getPageData,
                    pageTotal :pageTotal,
                    page : page
                })
            }else{
                Tools.showErrorToast(getDealRecordSuccess.data.message)
            }
        }, function () {
            Tools.hideLoaddingToast();
            Tools.showWrongNetWorkToast();
        })
    },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
      this.setData({
          dataSource : [],
          page : 0,
          pageTotal : 0
      });
      this.getDealRecordList(1);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let that = this;
      let nowPage = that.data.page;
      let pageTotal = that.data.pageTotal;
      if(nowPage < pageTotal){
          that.getDealRecordList(nowPage+1);
      }
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {}
});